package com.db.pck.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.db.core.vo.PageResult;
import com.db.core.vo.R;
import com.db.pck.entity.Package;
import com.db.pck.service.PackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：Bin
 * 时间：2023/11/1
 * 描述：键盘敲烂，薪资过万
 */
@RestController
@RequestMapping("pck")
@CrossOrigin
public class PackageController {

    @Autowired
    private PackageService packageService;

    @GetMapping("all")
    public R all(){
        return R.ok(packageService.list(),"success") ;
    }

    @PostMapping("add")
    public R add(@RequestHeader String token, @RequestBody Package apackage){
        return packageService.insert(apackage,token);
    }

    @PostMapping("edit")
    public R edit(@RequestHeader String token, @RequestBody Package apackage){
        return packageService.update(apackage,token);
    }

    @GetMapping("toggleStatus/{pckId}")
    public R toggleStatus(@PathVariable String pckId){
        return packageService.toggleStatus(pckId);
    }

    @GetMapping("delete/{pckId}")
    public R delete(@PathVariable String pckId){
        return packageService.deleteById(pckId);
    }
}
